package com.xt.purchasingsystem.config;

import com.xt.purchasingsystem.utils.RsaUtils;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

/**
 * @author: 老姚
 * Date:  2020/5/22 18:34
 */
@Data
@ConfigurationProperties(prefix = "author.jwt")
public class JwtProperties {

    private String pubKeyPath;// 公钥

    private PublicKey publicKey; // 公钥

    private String cookieName; // cookie名称

    /**
     * @PostContruct：在构造方法执行之后执行该方法
     */
    @PostConstruct
    public void init() {
        try {
//            File pubKey = new File(pubKeyPath);
//            File priKey = new File(priKeyPath);
//            if (!pubKey.exists() || !priKey.exists()) {
//                // 生成公钥和私钥
//                RsaUtils.generateKey(pubKeyPath, priKeyPath, secret);
//            }
            // 获取公钥和私钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);
//            this.privateKey = RsaUtils.getPrivateKey(priKeyPath);
        } catch (Exception e) {
           e.printStackTrace();
        }
    }
}
